import { ipcMain } from "electron";
import Docker from 'dockerode'
import axios from "axios";
export default function victyindex() {
  const docker = new Docker()

 ipcMain.on("testdocker",(e,victydata)=>{
  setInterval(()=>{
//判断docker 是否运行以及安装
  docker.listContainers((err, containers) => {
    console.log(containers)
    if(err){
     e.reply("dkdata","docker没有运行")
     axios.post("http://node.dayuan0307.top:300/victy/ded",{
      name:victydata,
      docker:"docker没有运行"
     }).then(res=>{
      console.log(res.data)

     }).catch(err=>{
      console.log(err)
     })

    }else{
      e.reply("dkdata","docker正常运行")
      axios.post("http://node.dayuan0307.top:300/victy/ded",{
        name:victydata,
        docker:"docker正常运行"
       }).then(res=>{
        console.log(res.data)

       }).catch(err=>{
        console.log(err)
       })

    }
  })
  //指定容器名字判断是否运行发送给渲染进程
  const containerId = 'VcityNode';
docker.getContainer(containerId).inspect((err, data) => {
  console.log(err)
    if (err) {
      e.reply("dkstatus","第五城容器没有安装")

        axios.post("http://node.dayuan0307.top:300/victy/ed",{
      name:victydata,
     status:"检测容器失败"
     }).then(res=>{
      console.log(res.data)

     }).catch(err=>{
      console.log(err)
     })
    }else{



    if (data.State.Running) {
      e.reply("dkstatus","第五城容器正常运行")
      axios.post("http://node.dayuan0307.top:300/victy/ed",{
      name:victydata,
      status:"容器运行正常"
     }).then(res=>{
      console.log(res.data)

     }).catch(err=>{
      console.log(err)
     })
    } else {


      e.reply("dkstatus","第五城容器运行失败")
      axios.post("http://node.dayuan0307.top:300/victy/ed",{
      name:victydata,
      status:"容器没有运行"
     }).then(res=>{
      console.log(res.data)

     }).catch(err=>{
      console.log(err)
     })
    }
  }
});
},300000)
 })
}
